import axios from '@/utils/request'

// const filterUserRemoteMethod = (query, context) => {
// axios
//   .get(`/manage/users`, { params: {
//     '@filter': `
//       entity.getUsername() == "${query}"
//       || entity.getId() == "${query}"
//     `
//   }})
//   .then(res => {
//     context.data = res.data.map(v => {
//       return { value: v.id, label: `${v.id}: ${v.__toString}` }
//     })
//   })
// }

const TYPE = {
  '-0-': '--- 普通 ---',
  'deposit': '收款',
  'burn-to-destroy': '提现',
  'deposit-fee': '支付费率',
  'deposit-from-mint': '提现失败返回',
  'order-settle-user': '订单分账'
}

export default {
  FianaceTransaction: {
    entity: { name: 'Transaction', prefix: () => `finance` },
    list: {
      export: {
        query: {
          '@display': `{
          'status' : '{ "failed": "失败", "pending": "等待", "success": "成功" }[entity.getStatus()]',
          'type' : '${JSON.stringify(TYPE)}[entity.getType()]',
          'amount' : 'entity.getAmount()',
          'from' : 'entity.getFrom().getUsername() == "admin"  ? "平台" : entity.getFrom().getUsername()',
          'to' : 'entity.getTo().getUsername() == "platform"  ? "平台" : entity.getTo().getUsername()',
          'createdTime' : 'entity.getCreatedTime().format("Y-m-d H:i:s")'
        }`,
          limit: 10000000
        },
        label: {
          'status': '状态',
          'type': '类型',
          'amount': '金额',
          'from': '借方',
          'to': '贷方',
          'createdTime': '创建时间'
        }
      },
      disabled_actions: ['new', 'lines'],
      query: {
        '@order': 'entity.id | DESC'
      },
      list_filter: {
        'category': {
          expression: '(entity.getfrom() == ":value" || entity.getTo() == ":value")',
          label: '账号',
          type: 'input' // Types: select, remote-select, input, datetime, date, time
        },
        type: Object.assign({ __label: '类型' }, TYPE),
        status: {
          '__label': '状态',
          'failed': '失败',
          'pending': '等待',
          'success': '成功'
        },
        startTime: {
          expression: `
          entity.getCreatedTime() >= datetime.get(":value")
        `,
          label: '开始时间',
          type: 'datetime'
        },
        endTime: {
          expression: `
          entity.getCreatedTime() < datetime.get(":value")
        `,
          label: '结束时间',
          type: 'datetime'
        }
      },
      list_display: [
        'id',
        // { property: 'hash', label: '哈希' },
        {
          property: 'status', label: '状态',
          component: {
            methods: {
              filter: (type, status) => [
                { value: 'failed', label: '失败', tagType: 'danger' },
                { value: 'pending', label: '等待', tagType: 'warning' },
                { value: 'success', label: '成功', tagType: 'success' }
              ].find(obj => obj.value === status)[type]
            },
            props: ['data'],
            render(h) {
              return (
                <el-tag type={this.filter('tagType', this.data)}>
                  {this.filter('label', this.data)}
                </el-tag>
              )
            }
          }
        },
        {
          property: 'type', label: '类型',
          component: {
            props: ['data'],
            render(h) {
              return <span>{TYPE[this.data]}</span>
            }
          }
        },
        {
          property: 'amount', label: '金额',
          component: {
            props: ['data'],
            render(h) {
              return <span>￥{this.data}</span>
            }
          }
        },
        {
          property: 'from',
          label: '借方',
          component: {
            props: ['data'],
            render(h) {
              console.log('aa',this.data)
              if (this.data.__toString === 'admin' || this.data.__toString === 'platform') {
                return (
                  <div>平台</div>
                )
              } else {
                return (
                  <div>{this.data.__toString}</div>
                )
              }
            }
          }
        },
        {
          property: 'to',
          label: '贷方',
          component: {
            props: ['data'],
            render(h) {
              if (this.data.__toString === 'admin' || this.data.__toString === 'platform') {
                return (
                  <div>支付平台</div>
                )
              } else {
                return (
                  <div>{this.data.__toString}</div>
                )
              }
            }
          }
        },
        'createdTime'
      ]
    },
    form: {
      fields: [
        'id'
      ]
    }
  }
}
